package com.example.main.mvp.view.fragment;


import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;


import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.lib_core.mvp.view.BaseFragment;
import com.example.main.R;
import com.example.main.adapter.TravelsAdapter;
import com.example.main.bean.TravelsBean;
import com.example.main.mvp.contract.MainContract;
import com.example.main.mvp.model.MainModel;
import com.example.main.mvp.presenter.MainPresenter;


import java.util.List;

import static com.example.main.app.Contants.ROUTER_MAIN_FRAGMENT;

@Route(path = ROUTER_MAIN_FRAGMENT)
public class MainFragment extends BaseFragment<MainPresenter> implements MainContract.View {

    private RecyclerView mRecyclerView;
    private TravelsAdapter travelsAdapter;

    @Override
    public int bondLayout() {
        return R.layout.fragment_main;
    }

    @Override
    public void initView() {
        mRecyclerView = findViewById(R.id.f_main_recycler_view);
        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    }

    @Override
    public void inJect() {
        mPresenter = new MainPresenter(new MainModel(), this);
    }
    @Override
    public void initData() {
        mPresenter.getTravelsBean();
    }

    @Override
    public void initAdapter(List<TravelsBean> travelsBeans) {
        if (travelsAdapter == null) {
            travelsAdapter = new TravelsAdapter(travelsBeans);
            mRecyclerView.setAdapter(travelsAdapter);
        } else {
            travelsAdapter.getData().addAll(travelsBeans);
            travelsAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public int currPage() {
        return 1;
    }


}
